<title>测试frmae用信息列表</title>

<div style="margin: 10px">
    <table id="testIframeTable" lay-filter="testIframeTable"></table>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="testIframeHeaderToolsBar">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="add">
            <i class="layui-icon layui-icon-add-1"></i>
            <span>新增</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="delete">
            <i class="layui-icon layui-icon-delete"></i>
            <span>删除</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="clears">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </a>
    </div>
    <form class="layui-form" action="" lay-filter="testIframeQueryForm" style="margin-right: 30px;">
        <div class="layui-row" style="margin-top: 10px;">
            <div class="selch table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label">主键ID</label>
                        <input type="text" class="layui-input filter-value" name="Q_id_SL" placeholder="主键ID"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">书籍名称</label>
                        <input type="text" class="layui-input filter-value" name="Q_bookName_SL" placeholder="书籍名称"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">书籍作者</label>
                        <input type="text" class="layui-input filter-value" name="Q_bookAuthor_SL" placeholder="书籍作者"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">书籍价格</label>
                        <input type="text" class="layui-input filter-value" name="Q_bookPrice_L" placeholder="书籍价格"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">出版时间</label>
                        <input type="text" class="layui-input start_time filter-value" name="Q_beginBookDate_DL" placeholder="开始时间"/>
                        <span style="float:left;margin-left:38px;">—</span>
                        <input type="text" class="layui-input end_time filter-value" name="Q_endBookDate_DG" placeholder="结束时间" style="margin-left:38px;"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">备注</label>
                        <input type="text" class="layui-input filter-value" name="Q_bookNoot_SL" placeholder="备注"/>
                </div>
            </div>
        </div>
    </form>

</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="testIframeRightToolsBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    //一般直接写在一个js文件中
    layui.use(['table', 'setter', 'form', 'common','totalFilter','commons','jquery'], function () {
        var table = layui.table;
        var setter = layui.setter;
        var form = layui.form;
        var common = layui.common;
        var commons = layui.commons;
        var $ = layui.jquery;
        var totalFilter = layui.totalFilter;
        common.tableSort('testIframeTable');

        var tableH=commons.tabHeight('full-70');

        //第一个实例
        table.render({
            elem: '#testIframeTable'
            ,height:tableH
            ,autoSort:true  //是否排序
            ,url: serverPath.systemPath + setter.sysLinkPath + 'testIframe/list'
            ,page: true //开启分页
            ,toolbar: '#testIframeHeaderToolsBar'
            ,method: 'post'
            ,autoSort: false
            ,cols: [[ //表头
                {field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
                ,{type: 'checkbox', fixed: 'left'}
                ,{field: 'id', title: '主键ID',sort:true, sortname: 'id'}
                ,{field: 'bookName', title: '书籍名称',sort:true, sortname: 'book_name'}
                ,{field: 'bookAuthor', title: '书籍作者',sort:true, sortname: 'book_author'}
                ,{field: 'bookPrice', title: '书籍价格',sort:true, sortname: 'book_price'}
                //如需转换为:yyyy-MM-dd HH:mm:ss: return commons.timeData(d.bookDate,"1");
                //如需转换为HH:mm:ss: return commons.timeData(d.bookDate,"2");
                // 当前转换后的格式为yyyy-MM-dd: return commons.timeData(d.bookDate);
                ,{field: 'bookDate', title: '出版时间',sort:true, sortname: 'book_date',templet: function (d) {
                    return commons.timeData(d.bookDate);
                }}
                ,{field: 'bookNoot', title: '备注',sort:true, sortname: 'book_noot'}
                ,{
                    fixed: 'right',
                    align: 'center',
                    title: '管理',
                    toolbar: '#testIframeRightToolsBar'
                }
            ]]
        });

        totalFilter.init('testIframeTable');
        commons.reflashDate({startName:'.start_time',endName:'.end_time'});

        function reflashQuery(isClear) {
            common.tableConditionRender("testIframeTable","testIframeQueryForm",{where:{}},isClear);
        }

        table.on('toolbar(testIframeTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: ['新增数据'],
                        area: ['500px', '600px'],
                        content: serverPath.systemPath + setter.openPath + setter.sysLinkPath + "testIframe/view/add"
                    });
                    break;
                case 'delete':
                    var array = "";
                    for (var i = 0; i < data.length; i++) {
                        array+=data[i].id+",";
                    }
                    delFun(data,array);
                    break;
                case "query":
                    reflashQuery(false);
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    break;
                case "clears":
                    reflashQuery(true);
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    break;

            };
        });

        table.on('tool(testIframeTable)', function(obj) {
            var data = obj.data, //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
            switch(layEvent){
                case "edit":
                    layer.open({
                        type: 2,
                        area: ['500px', '600px'],
                        title: ['修改数据'],
                        content: serverPath.systemPath + setter.openPath + setter.sysLinkPath + 'testIframe/view/add?id='+data.id
                    });
                    break;
                case "del":
                    delFun(data,data.id);
                    break;
            }
        });

        function delFun(data,id) {
            if (data.length === 0) {
                layer.msg('请先选择一行数据!');
            } else {
                layer.confirm('确定删除当前数据吗?', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.systemPath + setter.sysLinkPath + "testIframe/del",
                        type: "post",
                        data: {id:id},
                        dataType: 'json',
                        success: function (data) {
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery(true);
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery(true);
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        }
                    })
                })
            }
        }

        window.Initialization = function () {
            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
        };
        /*刷新时间控件*/
        commons.reflashDate({startName:'.start_time',endName:'.end_time'});
        common.tableSort("testIframeTable",{show:window.Initialization});
    });
</script>